class Person implements Comparable
{
	String name;
	int id;
	/**
	 *	构造方法
	 */
	public Person() {};
	public Person(String name,int id)
	{
		this.name = name ;
		this.id = id;
	}

	/**
	 *  为了使用HashSet必须重载equals()
	 *	当Student对象的name之和id值分别相等时，这两个对象相等
	 */

	public  boolean equals(Object objectOther)
	 {
	  if(this == objectOther)
		  return true;
	  if(objectOther == null)
		  return false;
	  
	  Person other = (Person)objectOther;
	  return name.equals(other.name) && id == other.id;
	 }

	/**
	 *  为了使用HashSet必须重载 hashCode()
	 */	
		 
	public int hashCode()
	{
		 return 7 * name.hashCode() + 11 * new Integer(id).hashCode();
	}

	/**
	 *  重载 toString()
	 */
	public String toString()
	{
		return "Person[name=" + this.name + ",id=" + this.id + "]";
	}
	/**
	 * 实现Comparable接口，使其可用于TreeSet
	 */
	public int compareTo(Object object)
	{
		return id - ((Person)object).id ;
	}
}
